#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/wait.h>

int main()
{
  pid_t id = fork();

  //子进程
  if(id == 0)
  {
    char* const argv[]={
      "ls",
      "-a",
      "-l"
    };
    extern char** environ;
    sleep(1);
    //进程替换
    printf("execl begin\n");
    //execl("/usr/bin/ls","ls","-a","-l",NULL);
    //execl("./mytest","mytest",NULL);
    //execvp("ls",argv);
    execle("./mytest","mytest",NULL,environ);
    printf("execl end\n");
    exit(1);
  }

  //pid > 0;省略不写，肯定会执行父进程
  pid_t rid = waitpid(id,NULL,0);
  if(rid > 0)
  {
    printf("wait scuess\n");
  }
  return 0;
}
